package jxc.servlet.info.goods;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxc.data.hibernate.dao.GoodsDAO;
import jxc.data.hibernate.pojo.Goods;

/**
 * Servlet implementation class Delete
 */
@WebServlet(name = "DeleteGoods", urlPatterns = { "/info/goods/delete" })
public class Delete extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Delete() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id=request.getParameter("id");
		GoodsDAO dao=new GoodsDAO();
		Goods goods=dao.getById(id);
		if(goods==null){
			response.setCharacterEncoding("UTF-8");
			response.getWriter().print("商品未找到");
			return;
		}
		dao.delete(goods);
		dao.commit();
		response.setCharacterEncoding("UTF-8");
		response.getWriter().print("删除商品成功："+goods.getGoodsname()+" ["+goods.getId()+"]");
	}

}
